package com.sairui.xiaoruilib;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.widget.ImageView;

import java.lang.ref.WeakReference;

/**
 * Created by sunqiyong on 2018/4/9.
 */

public class XiaoRuiHeaderManager {
    private ImageView mMenu;
    private ImageView mRobot;
    private ImageView mVoice;
    private ImageView mHelp;
    private WeakReference<Activity> mActivity;
    private AnimationDrawable animationDrawable;

    public void setTitleClickListener(final TitleClickListener mTitleClickListener) {
        mMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTitleClickListener.headerClick(HeaderClickType.MENU_TYPE,v);
            }
        });
        mVoice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTitleClickListener.headerClick(HeaderClickType.VOICE_TYPE,v);
            }
        });
        mHelp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTitleClickListener.headerClick(HeaderClickType.HELP_TYPE,v);
            }
        });
    }

    public void setVoiceIcon(Boolean b){
        mVoice.setImageResource(b ? R.mipmap.ico_line_voice : R.mipmap.ico_voice_no);
    }

    public XiaoRuiHeaderManager(WeakReference<Activity> mActivity) {
        this.mActivity = mActivity;
        mMenu = mActivity.get().findViewById(R.id.menu);
        mRobot = mActivity.get().findViewById(R.id.robot_view);
        mVoice = mActivity.get().findViewById(R.id.voice_menu);
        mHelp = mActivity.get().findViewById(R.id.help_menu);
        animationDrawable = (AnimationDrawable) mRobot.getBackground();
        if (animationDrawable != null && !animationDrawable.isRunning()) {
            animationDrawable.start();
        }
    }

    public enum HeaderClickType {
        MENU_TYPE,
        VOICE_TYPE,
        HELP_TYPE
    }

    public interface TitleClickListener{
        void headerClick(HeaderClickType type, View view);
    }
}
